package modules

import (
	"github.com/juju/ratelimit"
	"time"
)

type rateLimit struct {
	bucket *ratelimit.Bucket
}

var RateLimit rateLimit

func (r *rateLimit) New() *ratelimit.Bucket {
	if r.bucket == nil {
		// 桶容量为10 每20秒往桶里生成一枚令牌
		r.bucket = ratelimit.NewBucket(20*time.Second, 10)
	}
	return r.bucket
}
